# Py2Blog

This is a blog written in python2 using flask

You can see how it works [here](https://blog.dynois.ga/)

# Whats powering it?:
- [Python](http://python.org/)
- [Flask](http://flask.pocoo.org/)
- [MongoDB](http://www.mongodb.org/)
- [Bootstrap 3](http://getbootstrap.com/)
- [jQuery](http://jquery.com)
- [Lightbox 2](https://github.com/lokesh/lightbox2)
- [Markdown](http://daringfireball.net/projects/markdown/syntax)
- [Polymer](http://www.polymer-project.org)


# What it can:
- create/preview/update/delete articles;
- create/update/delete users;
- search;
- atom feed.

# Requirements:
- mongoDB >= 2.2


# Installation:
`git clone https://notabug.org/Dynomite54/py2blog.git`

`cd py2blog`

`virtualenv --no-site-packages ./env`

`source ./env/bin/activate`

`pip install -r requirements.txt`


After this edit the `config.py` file

- Replace the `CONNECTION_STRING` variable with your own connection string;

- Replace the `DATABASE` variable to your own one;

- If the default collection names don't work for you please replace the `POSTS_COLLECTION`, `USERS_COLLECTION` and `USERS_COLLECTION` variables to any names you like;

- If you use this code on a production sever replace the `DEBUG` variable with `False`.

# Run:
Start `mongod`, then when you in project dir with actived environment just type in terminal

`python web.py`

or

`gunicorn web:app`


# Setting Up Gunicorn and Supervisor
What Gunicorn and Supervisor allows you to do is run py2blog using commands and not logged into venv.

First you will need to install Supervisor

Debian/Ubuntu
`apt-get install supervisor`

CentOS
``

Now that we have Supervisor installed we can go head and make configs for it. You are going to want 2 configs for this, One for Gunicorn and one for mongoDB

All of the configs are stored in `/etc/supervisor/conf.d/` so all you have to do is navigate to this directory and `nano py2blog.conf` now that you are in the blank document here is a example config.
```
[program:py2blog]
command=/home/user/py2blog/env/bin/gunicorn -b localhost:8000 -w 4 web:app
directory=/home/user/py2blog
user=user
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
```

And for mongoDB you can do
```
[program:modgod]
command=modgod
directory=/
user=root
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
```

Now that you added the config in there you will need to restart supervisor using `supervisorctl reload`

You also can use the following commands to stop and start it.

`supervisorctl start blog`

`supervisorctl start modgod`

and to stop it you can use `stop` instead of start
# Nginx
On the nginx side we use a proxy function.

here is a example file that you will put in `/etc/nginx/sites-enabled`
```
server {
    server_name urlhere;
    listen 80;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
    }
}
```
you can now test the config using
`nginx -t`

And then you can restart nginx
`service nginx reload`
# Usage:
When you run the application for the first time the "Install" page appears. You need to create a user profile and set some display settings on this page.

If you have an account on Gravatar and your logged-in email links to it, the userpic will display. It will be a random gravatar image if it doesn't.

All necessary MongoDB indexes will be created during the installation. A test text post will be created as well.

There should be at least one post and one user for the database to be installed. That is why it's impossible to delete the last post or user.

If you want to start it from scratch please remove all existing collections from your database and delete the browser session cookie. The Install page will show up again.



